package be.khl.kevinvranken.breekuit.entiteiten;

import be.khl.kevinvranken.breekuit.*;
import java.awt.Graphics;
import java.awt.Rectangle;

public abstract class Entiteit {

    protected double x;
    protected double y;
    protected Sprite sprite;
    protected double dx;
    protected double dy;
    private Rectangle botsing = new Rectangle();
    private Rectangle botsingAndere = new Rectangle();

    public Entiteit(String ref, int x, int y) {
        this.sprite = SpriteStore.get().getSprite(ref);
        this.x = x;
        this.y = y;
    }

    public void move(long delta) {
        // update the location of the entity based on move speeds

        x += (delta * dx) / 1000;
        y += (delta * dy) / 1000;
    }

    public void setHorizontalMovement(double dx) {
        this.dx = dx;
    }

    public void setVerticalMovement(double dy) {
        this.dy = dy;
    }

    public double getHorizontalMovement() {
        return dx;
    }

    public double getVerticalMovement() {
        return dy;
    }

    public void draw(Graphics g) {
        sprite.draw(g, (int) x, (int) y);
    }

    public int getX() {
        return (int) x;
    }

    public int getY() {
        return (int) y;
    }

    public boolean collidesWith(Entiteit other) {
        botsing.setBounds((int) x, (int) y, sprite.getWidth(), sprite.getHeight());
        getBotsingAndere().setBounds((int) other.x, (int) other.y, other.sprite.getWidth(), other.sprite.getHeight());

        return botsing.intersects(getBotsingAndere());
    }

    public abstract void collidedWith(Entiteit entiteit);

    public double getBreedte() {
        return sprite.getWidth();
    }

    public double getHoogte() {
        return sprite.getHeight();
    }

    public Rectangle getBotsingAndere() {
        return botsingAndere;
    }
}